/***
 *@name index
 *@author Administrator
 *@date 2021/7/24 19:58
 *@Description
 **/
//inquirer 用户与命令行交互工具
const inquirer = require('inquirer');
//一个用于下载git仓库的项目的模块
const download = require('download-git-repo')
//可以将文字输出到终端当中
const program = require('commander')
//node的文件读写的模块
const exists = require('fs').existsSync
//模块提供了一些工具函数，用于处理文件与目录的路径
const path = require('path')
//这个模块用于在终端里有显示载入动画
const ora = require('ora')
//获取用户主目录的路径
const home = require('user-home')
//将绝对路径转换为波形路径 比如/Users/sindresorhus/dev → ~/dev
const tildify = require('tildify')
//命令行添加颜色的库（console.log(chalk.blue('123456'))）
const chalk = require('chalk')
//是一个可以使用 UNIX 命令 rm -rf的模块
const rm = require('rimraf').sync
// const logger = require('../lib/logger')
// const generate = require('../lib/generate')
// const checkVersion = require('../lib/check-version')
// const warnings = require('../lib/warnings')
// const localPath = require('../lib/local-path')


const promptList = [
    {
        type: 'input',
        message: '你的名字是什么？',
        name: 'name',
        default: '孙琦'
    },
    {
        type: 'input',
        message: '你的手机号？',
        name: 'phone',
        validate: function (val) {
            if (val.match(/\d{11}/g)) {
                return true;
            }
            return '请输入11位数的手机号'
        }
    }
]

// inquirer.prompt(promptList).then(answers => {
//     console.log(answers)
// })

/**
 * Usage.
 */

program
    .usage('<template-name> [project-name]')
    .option('-c, --clone', 'use git clone')
    .option('--offline', 'use cached template')
/**
 * Help.
 */

program.on('--help', () => {
    console.log('  Examples:')
    console.log()
    console.log(chalk.gray('    # create a new project with an official template'))
    console.log('    $ vue init webpack my-project')
    console.log()
    console.log(chalk.gray('    # create a new project straight from a github template'))
    console.log('    $ vue init username/repo my-project')
    console.log()
})

function help () {
    program.parse(process.argv)
    if (program.args.length < 1) return program.help()
}
// help()

console.log(chalk.blue('   456789'))
const spinner = ora('Loading unicorns').start();

setTimeout(() => {
    spinner.color = 'yellow';
    spinner.text = 'Loading rainbows';
}, 1000);
spinner.start();//开始
spinner.stop();//结束
download(
    "direct:https://gitee.com/yunper/general-template.git",
    'test',
    { clone: true },
    err => {
        console.log(err)
    })
